<template>
	<!-- 新契约工作列表模块-集汇件审核 -->
	<div class="fillcontain">
		<!-- 查询条件 -->
		<div class="fastQuery">
			<el-row>
				<el-col :span="2" class="fastQuery_title"><i class="el-icon-tickets"></i><span> 查询条件</span></el-col>
				<el-col :span="10"></el-col>
				<el-col :span="4" class="moreCondition">
					<span v-if="!isShow" @click="showorhide">更多条件 <i class="el-icon-d-arrow-right"></i></span>
					<span v-if="isShow" @click="showorhide">收起 <i class="el-icon-d-arrow-left"></i></span>
				</el-col>
				<el-col :span="8"></el-col>
			</el-row>
		</div>
		<!-- 查询表单 -->
		<el-form v-show="isShow" :model="searchParams" ref="ruleForm" label-width="120px" class="search_container">
			<el-row>
				<el-col :span="6">
					<el-form-item label="分支公司" prop="companyid">
						<el-select clearable v-model="searchParams.companyid" placeholder="分公司" filterable>
							<el-option v-for="(key,value) in ssyMap" :key="key.sorgid" :label="key.sorgname" :value="key.sorgid"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="检出人" prop="checkoutid">
						<el-input clearable v-model="searchParams.checkoutid" placeholder="检出人"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="保单号" prop="chdrnum">
						<el-input clearable v-model="searchParams.chdrnum" oninput="if(value.length>8) value=value.slice(0,8)"
						 placeholder="保单号"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="受理号" prop="caseno">
						<el-input clearable v-model="searchParams.caseno" placeholder="受理号"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="电子投保标识" prop="appFrom">
						<el-select clearable v-model="searchParams.appFrom" placeholder="电子投保标识">
							<el-option v-for="item in appFroms" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="险种类型" prop="risk">
						<el-select clearable v-model="searchParams.risk" placeholder="险种类型">
							<el-option v-for="item in insmains" :key="item.value" :label="item.name" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="6">
					<el-form-item label="被保人" prop="insuredname">
						<el-input clearable v-model="searchParams.insuredname" placeholder="被保人"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="6" class="text_center">
					<el-button type="primary" icon="el-icon-search" @click="subGetList"></el-button>
					<el-button type="primary" plain icon="el-icon-refresh" @click="resetSearch"></el-button>
				</el-col>
			</el-row>

		</el-form>

		<div class="contain">
			<!-- 操作按钮 -->
			<el-row>
				<el-col :span="24" class="pb15 pt5">
					<el-button type="danger" style="margin-left: 10px;" plain @click="taskShunt('vepass')">审核通过
					</el-button>
					<el-button type="danger" style="margin-left: 10px;" plain @click="exchangeNode('end')">end单
					</el-button>
					<el-button type="danger" style="margin-left: 10px;" plain @click="lock()">加锁</el-button>
					<el-button type="danger" plain @click="unlock()">解锁</el-button>
				</el-col>
			</el-row>
			<!-- 查询结果列表 -->
			<div class="table_container">
				<el-table ref="multipleTable" v-loading="loading" :data="tableData" tooltip-effect="dark" highlight-current-row
				 header-cell-class-name="table-header-class" @selection-change="handleSelectionChange" empty-text="无符合查询条件任务"
				 @sort-change="changeTableSort" style="width:100%">
					<el-table-column type="selection" :selectable="interceptVip"></el-table-column>
					<el-table-column property="SCHKOUSRID" label="检出人" align='center' show-overflow-tooltip min-width="120"></el-table-column>
					<el-table-column property="REMARK05" label="外包商" align='center' show-overflow-tooltip min-width="100"></el-table-column>
					<el-table-column property="SRISK" label="保单类型" align='center' show-overflow-tooltip min-width="100"></el-table-column>
					<el-table-column property="SORGNAME" label="机构" align='center' show-overflow-tooltip min-width="50"></el-table-column>
					<el-table-column property="SCASENO" label="受理号" align='center' show-overflow-tooltip min-width="80"></el-table-column>
					<el-table-column property="SCHDRNUM" label="保单号" align='center' show-overflow-tooltip min-width="100"></el-table-column>
					<el-table-column property="SINSURED" label="被保险人" align='center' show-overflow-tooltip min-width="100"></el-table-column>
					<el-table-column property="CRTABLENAME" label="主合同名称" align='center' show-overflow-tooltip min-width="120"></el-table-column>
					<el-table-column property="STASKLEVEL" label="任务级别" align='center' sortable show-overflow-tooltip min-width="100"></el-table-column>
					<el-table-column property="SNODEDES" label="任务类型" align='center' sortable show-overflow-tooltip min-width="100"></el-table-column>
					<el-table-column property="SDEALTIME" label="最近处理时间" align='center' show-overflow-tooltip min-width="160"></el-table-column>
					<el-table-column property="REMARK01" label="多保单标识" align='center' show-overflow-tooltip min-width="100">
						<template slot-scope="scope">
							<el-link type="primary" @click="showMorePolicy(scope.row.policyholderno)" v-if="scope.row.remark01 == '0'" :disabled="!interceptVip(scope.row, scope.index)">{{scope.row.policyholderno}}
							</el-link>
							<el-link type="primary" v-if="scope.row.remark01 != '0'" :disabled="!interceptVip(scope.row, scope.index)">{{scope.row.policyholderno}}
							</el-link>
						</template>
					</el-table-column>
					<el-table-column property="SGROUPNO" label="组号" align='center' show-overflow-tooltip min-width="100"></el-table-column>
					<el-table-column property="taskChange" label="处理过程" align='center' show-overflow-tooltip min-width="80">
						<template slot-scope="scope">
							<el-link type="primary" @click="showChange(scope.row.taskno)" :disabled="!interceptVip(scope.row, scope.index)">任务流转</el-link>
							<!-- <span class="operationIcon ml10" @click="showChange(scope.row.STASKNO)">
                                <i class="el-icon-paperclip"></i>
                            </span> -->
						</template>
					</el-table-column>
					<el-table-column property="imageInfo" label="影像信息" align='center' show-overflow-tooltip min-width="80">
						<template slot-scope="scope">
							<span class="operationIcon" @click="showImageList(scope.row.SCASENO)" :style="{'pointer-events':!interceptVip(scope.row, scope.index) ? 'none': ''}">
								<i class=" el-icon-camera"></i>
							</span>
						</template>
					</el-table-column>
					<el-table-column fixed="right" label="操作" align='center' show-overflow-tooltip min-width="50">
						<template slot-scope="scope">
							<!-- <el-link type="primary" @click="showRemark(scope.row.STASKNO)">备注</el-link> -->
							<span class="operationIcon" @click="showRemark(scope.row.STASKNO)" :style="{'pointer-events':!interceptVip(scope.row, scope.index) ? 'none': ''}">
								<i class="el-icon-tickets"></i>
							</span>
						</template>
					</el-table-column>
				</el-table>
				<el-row>
					<el-col :span="24">
						<div class="pagination">
							<el-pagination background v-if='paginations.total > 0' :page-sizes="paginations.pageSizes" :page-size="paginations.pageSize"
							 :layout="paginations.layout" :total="paginations.total" :current-page='paginations.pageIndex' @current-change='handleCurrentChange'
							 @size-change='handleSizeChange'>
							</el-pagination>
						</div>
					</el-col>
				</el-row>
			</div>
		</div>

		<!-- 备注-->
		<cdfs-remark-list :taskNo="remarkTaskNo" :drawer="showRemarkFlag" @close="hideRemark"></cdfs-remark-list>
		<cdfs-task-change-list :taskNo="changeTaskNo" :drawer="showChangeFlag" @close="hideChange"></cdfs-task-change-list>
		<!-- 同被保人多保单-->
		<more-policy-list :business="'NB'" :policyholderno="morePolicyPolicyholderno" :drawer="showMorePolicyFlag" @close="hideMorePolicy"></more-policy-list>
		<!--影像列表-->
		<cdfs-image-list :drawer="showImageFlag" :applnum="showImageApplnum" @close="hideImageList"></cdfs-image-list>
	</div>
</template>

<script>
	import TaskConstants, {
		call
	} from "@/api/taskManager/common";
	import {
		cdfsExchangeNode,
		getSsyOrgMap,
		cdfsLock,
		cdfsUnlock
	} from "@/api/taskCenter/taskCommon";
	import constant from '@/utils/constant';
	import cdfsRemarkList from "../cdfsRemarkList";
	import cdfsTaskChangeList from "../CdfsTaskChangeList";
	import MorePolicyList from "../morePolicyList";
	import CdfsImageList from "@/page/common/cdfsImageList";
	import taskConstants, {
		getSelectList
	} from '@/utils/taskConstants';
	export default {
		components: {
			CdfsImageList,
			MorePolicyList,
			cdfsTaskChangeList,
			cdfsRemarkList
		},
		data() {
			return {
				ssyMap: {}, //机构对象
				isShow: false,
				remarkTaskNo: "",
				showRemarkFlag: false,
				changeTaskNo: "",
				showChangeFlag: false,
				morePolicyPolicyholderno: "",
				showMorePolicyFlag: false,
				showImageFlag: false,
				showImageApplnum: '',
				emptySearchParams: {},
				appFroms: [],
				searchParams: {
					routeid: 'vecheck', //集汇件审核节点
					caseno: "", //受理号
					chdrnum: "", //保单号
					risk: "", //险种类型
					insuredname: "", //被保人姓名
					companyid: "", //分公司
					checkoutid: "", //检出人
					appFrom: '',
					pageSize: "",
					pageNumber: "",
				},
				insmains: TaskConstants.insmain,
				orderList: constant.order,
				tableData: [],
				loading: false,
				//需要给分页组件传的信息
				paginations: {
					total: 0, // 总数
					pageIndex: 1, // 当前位于哪页
					pageSize: 10, // 1页显示多少条
					pageSizes: [5, 10, 15, 20], //每页显示多少条
					layout: "total, sizes, prev, pager, next, jumper" // 翻页属性
				},
				isFirstEnter:false
			}
		},
		created() {
			// this.getList();
			this.emptySearchParams = JSON.parse(JSON.stringify(this.searchParams));
		},
		activated() {
			this.getList();
			document.onkeydown = (event)=>{
				var e = event || window.event || arguments.callee.caller.arguments[0];
				if (e && e.keyCode == 113) {
					this.getList();
				}
			};
		},
		mounted() {
			setTimeout(()=>{
				this.isFirstEnter=true;
			},100)
			getSsyOrgMap().then(data => this.ssyMap = data);
			this.appFroms = getSelectList(taskConstants.appFrom);
		},
		methods: {

			showRemark(taskNo) {
				this.remarkTaskNo = taskNo;
				this.showRemarkFlag = true;
			},
			showChange(taskNo) {
				this.changeTaskNo = taskNo;
				this.showChangeFlag = true;
			},
			hideRemark() {
				this.remarkTaskNo = "";
				this.showRemarkFlag = false;
			},
			hideChange() {
				this.changeTaskNo = '';
				this.showChangeFlag = false;
			},
			showorhide() {
				this.isShow = !this.isShow;
			},
			showMorePolicy(morePolicyPolicyholderno) {
				this.morePolicyPolicyholderno = morePolicyPolicyholderno;
				this.showMorePolicyFlag = true;
			},
			hideMorePolicy() {
				this.morePolicyPolicyholderno = '';
				this.showMorePolicyFlag = false;
			},
			showImageList(applnum) {
				this.showImageApplnum = applnum;
				this.showImageFlag = true;
			},
			hideImageList() {
				this.showImageApplnum = '';
				this.showImageFlag = false;
			},
			show(){
				this.$store.dispatch('loading/CHANGE_LOADING', true);
			},
			hide(){
				this.$store.dispatch('loading/CHANGE_LOADING', false);
			},
			//加锁
			lock() {
				this.show();
				let arrTask = [];
				this.$refs.multipleTable.selection.forEach(item => {
					arrTask.push(item);
				});
				if (arrTask.length <= 0) {
					this.$message.error("请选择任务！");
					this.hide();
					return;
				}
				//加锁该任务，但该任务已经加锁
				let bCheck = true;
				let arrTaskno = [];
				for (var i = 0; i < arrTask.length; i++) {
					let item = arrTask[i]
					arrTaskno.push({
						staskno: item.STASKNO,
						srcNode: item.SROUTEID
					});
					if (item["SISCHEKOUT"] == "1") {
						bCheck = false;
						alert("受理号为：" + item["SCASENO"] + "的任务已经加锁，不能再次加锁");
						break;
					}
				}
				if (!bCheck) {
					return;
				}
				cdfsLock(arrTaskno).then(res => {
					this.$store.dispatch('loading/CHANGE_LOADING', false);
					if (res.resultCode == constant.SUCCESS) {
						this.getList();
					} else {
						this.$alert(res.resultMsg, '错误信息', {
							confirmButtonText: '确定',
							callback: action => {
								this.$message({
									type: 'error',
									message: `action: ${action}`
								});
							}
						});
					}
					this.hide();
				}).catch(err => {
					this.hide();
				})
			},
			//解锁
			unlock() {
				this.show();
				let arrTask = [];
				this.$refs.multipleTable.selection.forEach(item => {
					arrTask.push(item);
				});
				if (arrTask.length <= 0) {
					this.$message.error("请选择任务！");
					this.hide();
					return;
				}
				//加锁该任务，但该任务已经加锁
				let bCheck = true;
				let arrTaskno = [];
				for (var i = 0; i < arrTask.length; i++) {
					let item = arrTask[i]
					arrTaskno.push({
						staskno: item.STASKNO,
						srcNode: item.SROUTEID
					});
					if (item["SISCHEKOUT"] == "0") {
						bCheck = false;
						alert("受理号为：" + item["SCASENO"] + "的任务没有加锁，无须解锁");
						break;
					}
				}
				if (!bCheck) {
					return;
				}
				cdfsUnlock(arrTaskno).then(res => {
					if (res.resultCode == constant.SUCCESS) {
						this.getList();
					} else {
						this.$alert(res.resultMsg, '错误信息', {
							confirmButtonText: '确定',
							callback: action => {
								this.$message({
									type: 'error',
									message: `action: ${action}`
								});
							}
						});
					}
					this.hide();
				}).catch(err => {
					this.hide();
				})
			},
			// 查询列表
			getList() {
				this.paginations.total = 0;
				this.tableData = [];
				this.show();
				this.searchParams.pageNumber = this.paginations.pageIndex;
				this.searchParams.pageSize = this.paginations.pageSize;
				call(TaskConstants.apis.querynbvecheckList, this.searchParams, "POST").then(res => {
					console.log('参数', this.searchParams);
					console.log('结果', res);
					this.hide();
					if (res.resultCode == constant.SUCCESS && res.data && res.data.list.length) {
						this.paginations.total = res.data.total;
						this.tableData = res.data.list;
					} else {
						this.$message.error("无符合条件任务！");
					}

				}).catch(err => {
					this.hide();
				})
			},
			//任务流转
			exchangeNode(routeid) {
				this.show();
				let arr = [];
				this.$refs.multipleTable.selection.forEach(item => {
					arr.push(item["STASKNO"]);
				});
				if (arr.length <= 0) {
					this.$message.error("请选择任务！");
					this.hide();
					return;
				}
				cdfsExchangeNode(arr, routeid).then(res => {
					this.hide();
					if (res.resultCode == constant.SUCCESS) {
						this.getList();
					} else {
						this.$alert(res.resultMsg, '错误信息', {
							confirmButtonText: '确定',
							callback: action => {
								this.$message({
									type: 'error',
									message: `action: ${action}`
								});
							}
						});
						this.getList();
					}
				}).catch(err => {
					this.hide();
				})
			},
			/* 集汇件审核通过 */
			taskShunt(routeid){
				let arr = [];
				this.$refs.multipleTable.selection.forEach(item => {
					arr.push(item["STASKNO"]);
				});
				if (arr.length <= 0) {
					this.$message.error("请选择任务！");
					return;
				}
				let param = {
					taskList:arr,
					routeid:routeid
				}
				this.show();
				call(TaskConstants.apis.nbvecheckPass,param,"post").then(res =>{

				}).catch(err =>{

				})
			},
			// 每页多少条切换
			handleSizeChange(pageSize) {
				this.paginations.pageSize = pageSize;
				this.getList();
			},
			// 上下分页
			handleCurrentChange(page) {
				this.paginations.pageIndex = page;
				this.getList();
			},
			// 根据条件查询列表
			subGetList() {
				this.paginations.pageIndex = 1;
				this.getList();
			},

			handleSelectionChange(val) {
				this.multipleSelection = val;
			},

			// 清除查询条件
			resetSearch() {
				this.searchParams = JSON.parse(JSON.stringify(this.emptySearchParams));
			},
			//选择指定列进行排序
			changeTableSort(column) {
				debugger;
				console.log(column);
				//获取字段名称和排序类型
				var fieldName = column.prop;
				var sortingType = column.order;
				//按照降序排序
				if (sortingType == "descending") {
					if (fieldName == "nodeName") {
						this.searchParams.taskTypeOrder = "routeid desc";
					}
					if (fieldName == "taskLevel") {
						this.searchParams.taskLevelOrder = "task_level desc";
					}
					if (fieldName == "dealtime") {
						this.searchParams.taskDealtimeOrder = "dealtime desc";
					}
				} else {
					//按照升序排序
					if (fieldName == "nodeName") {
						this.searchParams.taskTypeOrder = "routeid asc";
					}
					if (fieldName == "taskLevel") {
						this.searchParams.taskLevelOrder = "task_level asc";
					}
					if (fieldName == "dealtime") {
						this.searchParams.taskDealtimeOrder = "dealtime asc";
					}
				}
				this.getList();
				console.log(this.tableData);
			},
      // vip权限拦截
      interceptVip(row, index) {
        let rowStr = JSON.stringify(row);
        if (rowStr.indexOf("*") > -1) {
          return false;
        }
        return true;
      },
		},


	}
</script>

<style lang="less" scoped>
	.fillcontain {
		padding-bottom: 0;

		.fastQuery {
			padding: 15px 20px 10px 20px;
			background: #fff;
			border-bottom: 1px solid #e1e1e1;

			.fastQuery_title {
				color: #666;
				padding: 6px 0px;
			}

			.fastQuery_item {
				margin: 0 10px;
			}

			.item_default {
				.el-button {
					color: #409EFF !important;
					border-color: #c6e2ff !important;
					background-color: #ecf5ff !important;
				}

			}

			.moreCondition {
				color: #68a3fc;
				cursor: pointer;
				padding: 6px 0px;

				.el-icon-d-arrow-right {
					transform: rotate(90deg);
				}

				.el-icon-d-arrow-left {
					transform: rotate(-90deg);
				}
			}
		}
	}

	.contain {
		background: #fff;
		padding: 10px;
		margin-bottom: 20px;
	}

	.pagination {
		padding: 10px 20px;
		text-align: right;
	}

	.operationIcon {
		// padding: 12px;
		border: 1px solid #e5e5e5;
		border-radius: 50%;
		width: 22px;
		height: 22px;
		display: inline-block;
		cursor: pointer;
		box-shadow: 0 0 3px #f9f9f9;

		.svg-icon {
			font-size: 14px;
			fill: #68a3fc;
		}
	}

	.search_container {
		padding: 20px 20px 0 20px;
	}

	.el-dropdown {
		vertical-align: top;
	}

	.el-dropdown+.el-dropdown {
		margin-left: 15px;
	}

	.el-icon-arrow-down {
		font-size: 12px;
	}
</style>
